package com.test.exam.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.exam.commons.PageHelper;
import com.test.exam.dao.CourseDao;
import com.test.exam.domain.Course;

@Service
public class CourseService {
	private final int COURSE_ROW_PER_PAGE = 3; 
	
	@Autowired
	private CourseDao courseDao;
	
	// end page
	public int getEndPage(){
		int count = courseDao.getCourseCount();
		if(count == 0){
			return 0;
		}
		return (int)(Math.ceil((float)count/(float)COURSE_ROW_PER_PAGE));
	}
	
	//페이지 코스 목록
	public List<HashMap> getCoursesByCurrentPage(int currentPage){
		PageHelper pageHelper = new PageHelper();
		pageHelper.setRowPerPage(COURSE_ROW_PER_PAGE);
		pageHelper.setStartRow(currentPage);
		
		return courseDao.getCoursesByCurrentPage(pageHelper);
	}
	
	
	public int addCourse(Course course){
		return courseDao.addCourse(course);
	}
	

}
